// bcbergscorepage.cpp : implementation file
//

#include "stdafx.h"
#include "../Frame/GYWalkAidApp.h"
#include "BCBergScorePage.h"
#include "../Common/CommonFun.h"
#include "../Common/GYDataSet.h"
#include "../Common/LinkComboBox.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



static INPUT_FIELD_INFO s_InputFieldArray1[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("90"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("100"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("110"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("120"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("130"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("140"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("150"),		ftString,	FALSE,	0,	2,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray2[] = 
{
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("90"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("100"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("110"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("120"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("130"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("140"),		ftString,	FALSE,	0,	1,		NULL,		NULL	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("150"),		ftString,	FALSE,	0,	2,		NULL,		NULL	},
};

static INPUT_FIELD_INFO s_InputFieldArray3[] = 
{
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("10"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("20"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("30"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("40"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("50"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("60"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("70"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("80"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("90"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("100"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("110"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("120"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("130"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	FALSE,	TRUE,	_T("140"),		ftString,	FALSE,	0,	1,		CBCBergScorePage::ScoreFieldsCheck,	CBCBergScorePage::ScoreFieldsCheck	},
	{NULL,		IBT_NoneType,	TRUE,	TRUE,	_T("150"),		ftString,	FALSE,	0,	2,		NULL,								NULL	},
};


/////////////////////////////////////////////////////////////////////////////
// CBCBergScorePage dialog


CBCBergScorePage::CBCBergScorePage(CWnd* pParent, BOOL bBigRes) : CScrollPage(bBigRes ? CBCBergScorePage::IDD : CBCBergScorePage::SD_IDD, pParent)
, m_edtBerg101(&m_InputFieldArray1[0]),		m_edtBerg201(&m_InputFieldArray2[0]),	m_edtBerg301(&m_InputFieldArray3[0])
, m_edtBerg102(&m_InputFieldArray1[1]),		m_edtBerg202(&m_InputFieldArray2[1]),	m_edtBerg302(&m_InputFieldArray3[1])
, m_edtBerg103(&m_InputFieldArray1[2]),		m_edtBerg203(&m_InputFieldArray2[2]),	m_edtBerg303(&m_InputFieldArray3[2])
, m_edtBerg104(&m_InputFieldArray1[3]),		m_edtBerg204(&m_InputFieldArray2[3]),	m_edtBerg304(&m_InputFieldArray3[3])
, m_edtBerg105(&m_InputFieldArray1[4]),		m_edtBerg205(&m_InputFieldArray2[4]),	m_edtBerg305(&m_InputFieldArray3[4])
, m_edtBerg106(&m_InputFieldArray1[5]),		m_edtBerg206(&m_InputFieldArray2[5]),	m_edtBerg306(&m_InputFieldArray3[5])
, m_edtBerg107(&m_InputFieldArray1[6]),		m_edtBerg207(&m_InputFieldArray2[6]),	m_edtBerg307(&m_InputFieldArray3[6])
, m_edtBerg108(&m_InputFieldArray1[7]),		m_edtBerg208(&m_InputFieldArray2[7]),	m_edtBerg308(&m_InputFieldArray3[7])
, m_edtBerg109(&m_InputFieldArray1[8]),		m_edtBerg209(&m_InputFieldArray2[8]),	m_edtBerg309(&m_InputFieldArray3[8])
, m_edtBerg110(&m_InputFieldArray1[9]),		m_edtBerg210(&m_InputFieldArray2[9]),	m_edtBerg310(&m_InputFieldArray3[9])
, m_edtBerg111(&m_InputFieldArray1[10]),	m_edtBerg211(&m_InputFieldArray2[10]),	m_edtBerg311(&m_InputFieldArray3[10])
, m_edtBerg112(&m_InputFieldArray1[11]),	m_edtBerg212(&m_InputFieldArray2[11]),	m_edtBerg312(&m_InputFieldArray3[11])
, m_edtBerg113(&m_InputFieldArray1[12]),	m_edtBerg213(&m_InputFieldArray2[12]),	m_edtBerg313(&m_InputFieldArray3[12])
, m_edtBerg114(&m_InputFieldArray1[13]),	m_edtBerg214(&m_InputFieldArray2[13]),	m_edtBerg314(&m_InputFieldArray3[13])
, m_edtBerg115(&m_InputFieldArray1[14]),	m_edtBerg215(&m_InputFieldArray2[14]),	m_edtBerg315(&m_InputFieldArray3[14])
{
	//{{AFX_DATA_INIT(CBCBergScorePage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	LPVOID pCtrl = NULL;
	DWORD dwControlType = IBT_NoneType;
	for(int i = 0; i < INPUT_EDIT_CTRL_COUNT; i++)
	{
		pCtrl = m_InputFieldArray1[i].pLinkCtrl;
		dwControlType = m_InputFieldArray1[i].dwCtrlType;
		memcpy(&m_InputFieldArray1[i], &s_InputFieldArray1[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray1[i].pLinkCtrl = pCtrl;
		m_InputFieldArray1[i].dwCtrlType = dwControlType;
		
		pCtrl = m_InputFieldArray2[i].pLinkCtrl;
		dwControlType = m_InputFieldArray2[i].dwCtrlType;
		memcpy(&m_InputFieldArray2[i], &s_InputFieldArray2[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray2[i].pLinkCtrl = pCtrl;
		m_InputFieldArray2[i].dwCtrlType = dwControlType;

		pCtrl = m_InputFieldArray3[i].pLinkCtrl;
		dwControlType = m_InputFieldArray3[i].dwCtrlType;
		memcpy(&m_InputFieldArray3[i], &s_InputFieldArray3[i], sizeof(INPUT_FIELD_INFO));
		m_InputFieldArray3[i].pLinkCtrl = pCtrl;
		m_InputFieldArray3[i].dwCtrlType = dwControlType;
	}
}


void CBCBergScorePage::DoDataExchange(CDataExchange* pDX)
{
	CScrollPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBCBergScorePage)
	DDX_Control(pDX, IDC_EDIT_SCORE1, m_edtBerg101);
	DDX_Control(pDX, IDC_EDIT_SCORE4, m_edtBerg102);
	DDX_Control(pDX, IDC_EDIT_SCORE7, m_edtBerg103);
	DDX_Control(pDX, IDC_EDIT_SCORE10, m_edtBerg104);
	DDX_Control(pDX, IDC_EDIT_SCORE13, m_edtBerg105);
	DDX_Control(pDX, IDC_EDIT_SCORE16, m_edtBerg106);
	DDX_Control(pDX, IDC_EDIT_SCORE19, m_edtBerg107);
	DDX_Control(pDX, IDC_EDIT_SCORE22, m_edtBerg108);
	DDX_Control(pDX, IDC_EDIT_SCORE25, m_edtBerg109);
	DDX_Control(pDX, IDC_EDIT_SCORE28, m_edtBerg110);
	DDX_Control(pDX, IDC_EDIT_SCORE31, m_edtBerg111);
	DDX_Control(pDX, IDC_EDIT_SCORE34, m_edtBerg112);
	DDX_Control(pDX, IDC_EDIT_SCORE37, m_edtBerg113);
	DDX_Control(pDX, IDC_EDIT_SCORE40, m_edtBerg114);
	DDX_Control(pDX, IDC_EDIT_SCORE43, m_edtBerg115);

	DDX_Control(pDX, IDC_EDIT_SCORE2, m_edtBerg201);
	DDX_Control(pDX, IDC_EDIT_SCORE5, m_edtBerg202);
	DDX_Control(pDX, IDC_EDIT_SCORE8, m_edtBerg203);
	DDX_Control(pDX, IDC_EDIT_SCORE11, m_edtBerg204);
	DDX_Control(pDX, IDC_EDIT_SCORE14, m_edtBerg205);
	DDX_Control(pDX, IDC_EDIT_SCORE17, m_edtBerg206);
	DDX_Control(pDX, IDC_EDIT_SCORE20, m_edtBerg207);
	DDX_Control(pDX, IDC_EDIT_SCORE23, m_edtBerg208);
	DDX_Control(pDX, IDC_EDIT_SCORE26, m_edtBerg209);
	DDX_Control(pDX, IDC_EDIT_SCORE29, m_edtBerg210);
	DDX_Control(pDX, IDC_EDIT_SCORE32, m_edtBerg211);
	DDX_Control(pDX, IDC_EDIT_SCORE35, m_edtBerg212);
	DDX_Control(pDX, IDC_EDIT_SCORE38, m_edtBerg213);
	DDX_Control(pDX, IDC_EDIT_SCORE41, m_edtBerg214);
	DDX_Control(pDX, IDC_EDIT_SCORE44, m_edtBerg215);

	DDX_Control(pDX, IDC_EDIT_SCORE3, m_edtBerg301);
	DDX_Control(pDX, IDC_EDIT_SCORE6, m_edtBerg302);
	DDX_Control(pDX, IDC_EDIT_SCORE9, m_edtBerg303);
	DDX_Control(pDX, IDC_EDIT_SCORE12, m_edtBerg304);
	DDX_Control(pDX, IDC_EDIT_SCORE15, m_edtBerg305);
	DDX_Control(pDX, IDC_EDIT_SCORE18, m_edtBerg306);
	DDX_Control(pDX, IDC_EDIT_SCORE21, m_edtBerg307);
	DDX_Control(pDX, IDC_EDIT_SCORE24, m_edtBerg308);
	DDX_Control(pDX, IDC_EDIT_SCORE27, m_edtBerg309);
	DDX_Control(pDX, IDC_EDIT_SCORE30, m_edtBerg310);
	DDX_Control(pDX, IDC_EDIT_SCORE33, m_edtBerg311);
	DDX_Control(pDX, IDC_EDIT_SCORE36, m_edtBerg312);
	DDX_Control(pDX, IDC_EDIT_SCORE39, m_edtBerg313);
	DDX_Control(pDX, IDC_EDIT_SCORE42, m_edtBerg314);
	DDX_Control(pDX, IDC_EDIT_SCORE45, m_edtBerg315);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBCBergScorePage, CScrollPage)
	//{{AFX_MSG_MAP(CBCBergScorePage)
	ON_WM_VSCROLL()
	ON_WM_SIZE()
	ON_WM_MOUSEWHEEL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBCBergScorePage message handlers

void CBCBergScorePage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	//...

	CScrollPage::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CBCBergScorePage::OnSize(UINT nType, int cx, int cy) 
{
	CScrollPage::OnSize(nType, cx, cy);
	
	//...
}

BOOL CBCBergScorePage::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	//...

	return CScrollPage::OnMouseWheel(nFlags, zDelta, pt);
}

BOOL CBCBergScorePage::ClearData()
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_DATE_3);

	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	return PageClearData(ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, ARRAY_ELE_COUNT(apDateLabel));
}

int CBCBergScorePage::SaveData(CString strMRN, int nDiagSN, BOOL bIsDraft)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	return PageSaveData(strMRN, nDiagSN, bIsDraft, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBergScorePage::ScoreFieldsCheck(LPVOID pParam)
{
	CBCBergScorePage* pParent = NULL;
	INPUT_FIELD_INFO* pFieldInfo = (INPUT_FIELD_INFO*)pParam;

	if(pFieldInfo->dwCtrlType == IBT_EditBox)
	{
		CLinkEdit* pEdit = (CLinkEdit*)pFieldInfo->pLinkCtrl;
		if(pEdit)
			pParent = (CBCBergScorePage*)pEdit->GetParent();
	}
	else if(pFieldInfo->dwCtrlType == IBT_ComboBox)
	{
		CLinkComboBox* pCombo = (CLinkComboBox*)pFieldInfo->pLinkCtrl;
		if(pCombo)
			pParent = (CBCBergScorePage*)pCombo->GetParent();
	}
	else
	{
		ASSERT(FALSE);
	}

	if(pParent == NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	return PageScoreFieldsCheck(pParam, 0, 4, pParent->m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBergScorePage::ShowTableDataWithStartCol(CString strMRN, int nDiagSN, int nStartCol)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;
	
	CWnd* apDateLabel[3];
	apDateLabel[0] = GetDlgItem(IDC_STATIC_DATE_1);
	apDateLabel[1] = GetDlgItem(IDC_STATIC_DATE_2);
	apDateLabel[2] = GetDlgItem(IDC_STATIC_DATE_3);
	
	CWnd* apDiagSNArray[3];
	apDiagSNArray[0] = GetDlgItem(IDC_STATIC_DIAGSN1);
	apDiagSNArray[1] = GetDlgItem(IDC_STATIC_DIAGSN2);
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);
	
	return PageShowTableData(strMRN, nDiagSN, BODYCHECKSCALEID, ppCtrlArray, INPUT_EDIT_CTRL_COUNT, apDateLabel, apDiagSNArray, nStartCol);
}

BOOL CBCBergScorePage::ShowTableData(CString strMRN, int nDiagSN)
{
	return ShowTableDataWithStartCol(strMRN, nDiagSN, 2);
}

BOOL CBCBergScorePage::EnableInputControls(BOOL bEnable)
{
	INPUT_FIELD_INFO* ppCtrlArray[3];
	ppCtrlArray[0] = m_InputFieldArray1;
	ppCtrlArray[1] = m_InputFieldArray2;
	ppCtrlArray[2] = m_InputFieldArray3;

	return PageEnableInputControls(bEnable, ppCtrlArray, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBergScorePage::IsPageCurDayBlank()
{
	return CScrollPage::PageIsAllInputBlank(m_InputFieldArray3, INPUT_EDIT_CTRL_COUNT);
}

BOOL CBCBergScorePage::SetLastColTitile(CString strDate, int nDiagSN)
{
	CWnd* apDateLabel[3] = {0};
	apDateLabel[2] = GetDlgItem(IDC_STATIC_DATE_3);

	CString astrDate[3];
	astrDate[2] = strDate;
	
	CWnd* apDiagSNArray[3] = {0};
	apDiagSNArray[2] = GetDlgItem(IDC_STATIC_DIAGSN3);

	int anDiagSN[3] = {0};
	anDiagSN[2] = nDiagSN;

	return PageShowColTitle(apDateLabel, astrDate, apDiagSNArray, anDiagSN, ARRAY_ELE_COUNT(apDateLabel));
}
